***********************************************************
* Letki, N., Górecki, M.A., & Gendźwiłł, A. (2022). They accept bribes, we accept bribery: Conditional effects of corrupt encounters on evaluation of public institutions
*
* Replication syntax
*
* 19/01/2022
*

clear all

frame create data
frame change data

use "F:\My Drive\Naukowe\Corruption\corruption_final.dta", clear


*VARIABLES

*eval_rev2 			Evaluation of public institutions
*corr_exp			Corruption experience (D15)
*corruption 		Single bidding measure (proportion)
*cexp_corr			Interaction: Corruption experience*Proportion single bidding 
*no_tenders			Number of tenders
*sex				Gender (female) 
*age				Age 
*educ4				Education (Degree)
*unemployed			Unemployed 
*busi_own			Business owner 
*pub_sector 		Public sector employed 
*religiosity		Religiosity
*bad_health			Self-reported bad health
*child				Having children
*contact_new		Contacted one of the institutions (D08 recode)
*minority			Ethnic minority 
*length				Length of living in the neighborhood 
*urban 				Urban locality 
*unemployment_rate	Unemployment rate 
*log_pop			Population (logged)

* Evaluation of public institutions - raw:
* hospital_X taxoffice_X ministry_X locgov_X socsecurity_X police_X courts_X school_X (based on D08)
* X - dimensions (a, b, c, d, e, h, l) (based on D10)

*COUNTRY - country ID
*PSU_C - municipality ID
*w1 - weight

* Dependent variable: evaluation of public institutions (index)

*Average evaluations of institutions (missings treated as zeros)
capture drop eval_ministry eval_locgov eval_taxoffice eval_socsec eval_police eval_courts eval_hospital eval_school
egen eval_ministry=rowmean(ministry_a ministry_b ministry_c ministry_d ministry_e ministry_h ministry_l)
egen eval_locgov=rowmean(locgov_a locgov_b locgov_c locgov_d locgov_e locgov_h locgov_l)
egen eval_taxoffice=rowmean(taxoffice_a taxoffice_b taxoffice_c taxoffice_d taxoffice_e taxoffice_h taxoffice_l)
egen eval_socsec=rowmean(socsecurity_a socsecurity_b socsecurity_c socsecurity_d socsecurity_e socsecurity_h socsecurity_l)
egen eval_police=rowmean(police_a police_b police_c police_d police_e police_h police_l)
egen eval_courts=rowmean(courts_a courts_b courts_c courts_d courts_e courts_h courts_l)
egen eval_hospital=rowmean(hospital_a hospital_b hospital_c hospital_d hospital_e hospital_h hospital_l)
egen eval_school=rowmean(school_a school_b school_c school_d school_e school_h school_l)

* Evaluation of public institutions
* Reversing the scale
egen eval_rev2=rowmean(eval_locgov eval_taxoffice eval_socsec eval_police eval_courts eval_hospital eval_school)
replace eval_rev2=(eval_rev2*-1)+6

* No of tenders expressed in thousands
gen no_tendersK = no_tenders/1000

* sex --> female dummy var
gen female = sex - 1


*-----------------------------------
* Main models

*model 1
reg eval_rev2 corr_exp corruption no_tendersK female age educ4 unemployed busi_own pub_sector religiosity minority length urban unemployment_rate log_pop i.COUNTRY if no_tenders >=10 [pweight = w1], cluster(PSU_C)

estimates store model1

*model 2
reg eval_rev2 corr_exp corruption cexp_corr no_tendersK female age educ4 unemployed busi_own pub_sector religiosity minority length urban unemployment_rate log_pop i.COUNTRY if no_tenders >=10 [pweight = w1], cluster(PSU_C)

estimates store model2

* ols - flags observations used in the main model
gen ols=1 if e(sample)>0

etable, estimates(model1 model2) mstat(N) mstat(N_clust) mstat(r2_a) showstars stars(0.05 "*" 0.01 "**" 0.001 "***") showstarsnote

*---------------------------------------------------
* Figure 1 (Context-dependent effects of corrupt encounter on evaluations of public institutions)

* generates distribution of municipality size in a separate frame
frame copy data graph
frame change graph
collapse corruption if no_tenders >=10, by(PSU_C)
sort corruption
rename corruption value

* saves estimates for percentiles of corruption prevalence
gen effect=.
gen lci=.
gen uci=.

foreach i of numlist 1 10 25 50 75 90 95 99 {
	     frame change graph
		 summarize value if PSU_C!=0, detail
		 scalar p`i'= r(p`i')
		 frame change data
         lincom corr_exp + p`i'*cexp_corr
         frame post graph (0) (p`i') (r(estimate)) (r(lb)) (r(ub))
   }

* labels for point estimates
frame change graph
gen label=""
replace label = "99th (0.741)" if _n==_N
replace label = "95th (0.575)" if _n==_N-1
replace label = "90th (0.472)" if _n==_N-2
replace label = "75th (0.391)" if _n==_N-3
replace label = "50th (0.226)" if _n==_N-4
replace label = "25th (0.152)" if _n==_N-5
replace label = "10th (0.092)" if _n==_N-6
replace label = "1st (0.000)" if _n==_N-7

* final graph (fig. 1)
frame change graph
twoway (histogram value if PSU_C!=0, frequency bin(40) fcolor(gray) lcolor(gray) lwidth(vthin) ylabel(none, nolabels axis(2)) yaxis(2) yscale(alt) yscale(alt axis(2) range(0 200))) ///
(scatter effect value, mcolor(black) msymbol(circle) mlabel(label) mlabsize(small) mlabposition(5) mlabangle(90) yaxis(1) ) ///
(rspike lci uci value, lcolor(black) yaxis(1)), ///
ytitle("Effect of corrupt encounter""on evaluations of public institutions", axis(1)) ///
ytitle(., axis(2)) /// 
yline(0, lpattern(dash) lcolor(gray)) /// 
xtitle(Local context: single-bidding proportion) ///
legend(off) scheme(s1mono)

*--------------------------------------------
* Supplementary Material

* A2: descriptives (limited to observations included in OLS model)
* individual-level variables
frame change data
tabstat eval_rev2 corr_exp female age educ4 unemployed busi_own pub_sector bad_health child religiosity minority length if ols==1, statistics( count mean sd ) columns(statistics) format(%9.3f) 
* muncipality-level variables
frame copy data des
frame change des
decode COUNTRY, gen(country)
collapse corruption no_tenders urban unemployment_rate log_pop (first) country if ols==1, by(PSU_C)
tabstat corruption no_tenders urban unemployment_rate log_pop, statistics( count mean sd ) columns(statistics) format(%9.3f)

* A3: Evaluations and corruption measures, per country
* individual-level
frame change data
tabstat eval_rev2 corr_exp if ols==1, statistics( count mean sd ) columns(statistics) format(%9.3f) by(COUNTRY)
* municipality-level
frame change des
tabstat corruption, statistics( count mean sd ) columns(statistics) format(%9.3f) by(country)

* figure A1: Municipality-level distribution of single-bidding per country
frame change des
histogram corruption, fraction fcolor(gray) lcolor(gray) xtitle(Single-bidding proportion) by(, note(Only municipalities with at least 10 tenders are included.)) by(country, total) scheme(s1mono)

* Additional models
frame change data

* model A3.1 (Heckman selection model)
heckman eval_rev2 corr_exp corruption cexp_corr no_tendersK female age educ4 unemployed busi_own pub_sector religiosity minority length urban unemployment_rate log_pop i.COUNTRY if no_tenders>=10 [pweight = w1], select(contact_new = bad_health child unemployed busi_own female age) cluster(PSU_C)

estimates store heckman

* model A3.2 (3-level RE, model 2)
xtmixed eval_rev2 corr_exp corruption no_tendersK female age educ4 unemployed busi_own pub_sector religiosity minority length urban unemployment_rate log_pop [w=w1] if ols==1, ||COUNTRY: ||PSU_C:, var mle

estimates store ml1

*model A3.3 (3-level RE, model 3)
xtmixed eval_rev2 corr_exp corruption cexp_corr no_tendersK female age educ4 unemployed busi_own pub_sector religiosity minority length urban unemployment_rate log_pop [w=w1] if ols==1, ||COUNTRY: ||PSU_C:, var mle

estimates store ml2

etable, estimates(heckman ml1 ml2) mstat(N) mstat(N_clust) mstat(r2_a) showstars stars(0.05 "*" 0.01 "**" 0.001 "***") showstarsnote
